import {Menu, nativeImage} from 'electron'
import {mainWindow} from "@/main"
import { MsgChannel, ContentMenuType } from "@common/constants";

export function createContextMenu(menuType,data) {
  console.log(menuType,data)
  const quickIcon = nativeImage.createFromPath('./resources/asset/bolt.png').resize({ width: 16, height: 16 })
  const d2Icon = nativeImage.createFromPath('./resources/asset/d2.png').resize({ width: 16, height: 16 })
  const d3Icon = nativeImage.createFromPath('./resources/asset/cube.png').resize({ width: 16, height: 16 })
  const mprIcon = nativeImage.createFromPath('./resources/asset/mpr.png').resize({ width: 16, height: 16 })
  const compareIcon = nativeImage.createFromPath('./resources/asset/compare.png').resize({ width: 16, height: 16 })
  const exportIcon = nativeImage.createFromPath('./resources/asset/export.png').resize({ width: 16, height: 16 })
  const tagIcon = nativeImage.createFromPath('./resources/asset/tag.png').resize({ width: 16, height: 16 })
  const folderIcon = nativeImage.createFromPath('./resources/asset/folder.png').resize({ width: 16, height: 16 })

  const template = [
    {
      label: '快速浏览',
      icon: quickIcon,
      role: 'quick',
      click:() => clickHandler(ContentMenuType.quick,data)
    },
    {
      label: '2D',
      icon: d2Icon,
      role: '2D',
      enabled: false,
      click:() => clickHandler('2D',data)
    },
    {
      label: '3D',
      icon: d3Icon,
      role: '3D',
      enabled: false,
      click:() => clickHandler('3D',data)
    },

    {
      label: 'MPR浏览',
      icon: mprIcon,
      role: 'mpr',
      click:() => clickHandler(ContentMenuType.normal,data)
    },
    {
      label: '图像对比',
      icon: compareIcon,
      role: 'compare',
      enabled: false,
      click:() => clickHandler('compare',data)
    },

    { type: 'separator' },

    {
      label: '导出脱敏DICOM',
      icon: exportIcon,
      role: 'anonymizedExport',
      enabled: false,
      click:() => clickHandler('anonymizedExport',data)
    },
    {
      label: '查看DICOM标签',
      icon: tagIcon,
      role: 'tag',
      click:() => clickHandler('showTag',data)
    },
    { type: 'separator' },
    {
      label: '从列表移除',
      role: 'removeSeries',
      click:() => clickHandler(ContentMenuType.removeSeries,data)
    },
    {
      label: '另存为',
      role: 'saveAs',
      enabled: false,
      click:() => clickHandler(ContentMenuType.saveAs,data)
    },
    {
      label: '打开所在文件夹',
      icon: folderIcon,
      role: 'openFolder',
      click:() => clickHandler(ContentMenuType.openFolder,data)
    },
  ] as any;

  return Menu.buildFromTemplate(template);
}

const clickHandler = (type, data) => {
   mainWindow.webContents.send(MsgChannel.Menu.selectMenu, {
    type,
    data,
  });
}
